package com.ct.boot.launch.config;

import com.atomikos.jdbc.AtomikosDataSourceBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @Auther: Charles chen
 * @Date: 2020/7/16 12:45
 * @Description:
 */
@Configuration
public class dataSourceConfig {
//    @Primary
//    @Bean
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DataSource primaryDataSource(){
//        return DataSourceBuilder.create().build();
//    }
//    @Bean("secondaryDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.secondary")
//    public DataSource secondaryDataSource(){
//        return DataSourceBuilder.create().build();
//    }

//    @Bean
//    public JdbcTemplate primaryJdbcTemplate(DataSource dataSource){
//        return new JdbcTemplate(dataSource);
//    }
//    @Bean("secondaryJdbcTemplate")
//    public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource")  DataSource dataSource){
//        return new JdbcTemplate(dataSource);
//    }
    //分布式事务专用连接池数据源
//    @Bean(initMethod = "init",destroyMethod = "close",name = "primaryDataSource")
//    @Primary
//    @ConfigurationProperties(prefix = "primarydb")
//    public DataSource primaryDataSource(){
//        return new AtomikosDataSourceBean();
//    }
//    @Bean(initMethod = "init",destroyMethod = "close",name = "secondaryDataSource")
//    @ConfigurationProperties(prefix = "secondarydb")
//    public DataSource secondaryDataSource(){
//        return new AtomikosDataSourceBean();
//    }
//        @Bean("primaryJdbcTemplate")
//    public JdbcTemplate primaryJdbcTemplate(@Qualifier("primaryDataSource")  DataSource dataSource){
//        return new JdbcTemplate(dataSource);
//    }
//    @Bean("secondaryJdbcTemplate")
//    public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource")  DataSource dataSource){
//        return new JdbcTemplate(dataSource);
//    }
}
